﻿Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports BBDD
Imports Controladores

 _

Class comprarAccOper
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Session("privUser") Is Nothing Or Integer.Parse(Session("privUser").ToString()) < 1 Then
            Response.Redirect("index.aspx")
        Else
            If Integer.Parse(Session("privUser").ToString()) = 1 Then
                campoDNI.Text = Session("DNIUser").ToString()
                campoDNI.Enabled = False

            Else
                campoDNI.Enabled = True
            End If
        End If

        listaAcciones.Value = Consultas.listarAcciones()
    End Sub 'Page_Load


    Protected Sub boton_comprarValor_Click(ByVal sender As Object, ByVal e As EventArgs)
        If campoDNI.Text = "" Or Not Consultas.existeUsuario(campoDNI.Text.ToString()) Then
            controlador.CreateMessageAlert(Me, "No existe tal usuario", "msg")
        Else
            If campoCantidad.Text = "" Then
                campoCantidad.Text = "-1"
            End If

            If campoValor.Text = "" Then
                campoValor.Text = "-1"
            End If

            Dim campoMejor As Double = Convert.ToDouble(campoValor.Text.ToString())
            Session("error") = controlador.comprarAccionPorValor(campoDNI.Text.ToString(), campoSimboloEntrada.Text.ToString(), Integer.Parse(campoCantidad.Text.ToString()), campoMejor)
            If Session("error").ToString() = "" Then
                campoDNI.Enabled = False
                controlador.CreateMessageAlert(Me, "Operacion llevada con éxito", "msg")
                Me.campoCantidad.Text = ""
                Me.campoSimboloEntrada.Text = ""
                Me.campoValor.Text = ""
            End If
            campoDNI.Enabled = False
            controlador.CreateMessageAlert(Me, Session("error").ToString(), "msg")
        End If
    End Sub 'boton_comprarValor_Click
End Class 'comprarAccOper